#include<iostream>
#include<map>
using namespace std;
const int N = 1e3 + 10;
map<string, int>mp;
int p[N];
string s1, s2, s3;
int n;
int fun(string s)
{
	if (!mp[s]) {
		mp[s] = ++n;
	}
	return mp[s];
}
int find(int x)
{
	if (x != p[x])p[x] = find(p[x]);
	return p[x];
}
int main()
{
	int m;
	while (cin >> m, m) {
		for (int i = 1; i < N; i++) {
			p[i] = i;
		}
		mp.clear();
		n = 0;
		while (m--) {
			cin >> s1 >> s2 >> s3;
			int a = find(fun(s1));
			int b = find(fun(s2));
			int c = find(fun(s3));
			p[a] = c;
			p[b] = c;
		}
		cin >> s1 >> s2;
		int a = fun(s1);
		int b = fun(s2);
		if (find(a) == find(b))cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}